/*************************************************************************
 *                     COPYRIGHT NOTICE
 *            Copyright 2024 Horizon Robotics, Inc.
 *                   All rights reserved.
 *************************************************************************/
#include "gpu_sample_log.hpp"

static bool check_and_print_log_level(int32_t level)
{

	bool result = level <= GPU_SAMPLE_LOG_INFO;
	if (result) {
		std::fprintf(stderr, "GPU_SAMPLE_");
		switch (level)
		{
		case GPU_SAMPLE_LOG_NO_LOG:
			/* Reserved for no logging */
			break;
		case GPU_SAMPLE_LOG_ERROR:
			std::fprintf(stderr, "ERROR");
			break;
		case GPU_SAMPLE_LOG_WARNING:
			std::fprintf(stderr, "WARNING");
			break;
		case GPU_SAMPLE_LOG_INFO:
			std::fprintf(stderr, "INFO");
			break;
		default:
			std::fprintf(stderr, "LEVEL_%d", level);
			break;
		}
	}
	return result;
}

void gpu_sample_log_message(int32_t level, const char *file, int32_t line, const char *format, ...)
{
	if (check_and_print_log_level(level)) {
		std::fprintf(stderr, "(%s:%d): ", file, line);
		std::va_list args;
		va_start(args, format);
		std::vfprintf(stderr, format, args);
		va_end(args);
		std::putc('\n', stderr);
	}
}